package club.mzywucai.blog.file_system.controller;

import club.mzywucai.blog.file_system.pojo.domain.JsonData;
import club.mzywucai.blog.file_system.pojo.vo.FileBasicListQueryTermsVo;
import club.mzywucai.blog.file_system.service.FileInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author mzywucai
 * @Description
 * @date 2019/2/11
 */
@RestController
public class FileInformationController {
    @Autowired
    FileInformationService fileInformationService;

    /**
     * @Description 获取最近上传的文件列表
     * @author mzywucai
     * @time 2019-02-11
     * @see
     * @return   java.lang.Object
     * @params  []
     */
    @GetMapping("/api/recentUploadList")
    public Object getRecentIUploadFileVoList() {
        JsonData json = fileInformationService.getRecentIUploadFileVoList();

        return json;
    }

    /**
     * @Description 根据File的唯一ID，获取对应的文件详情
     * @author mzywucai
     * @time 2019-02-11
     * @see 
     * @return   java.lang.Object
     * @params  [fileInfoId]
     */
    @GetMapping("/api/fileDetail/{fileInfoId}")
    public Object getFileDetailVoByFileInfoId(@PathVariable("fileInfoId") Long fileInfoId) {
        if (null == fileInfoId) {
            fileInfoId = 0L;
        }

        JsonData json = fileInformationService.getFileDetailVoByFileInfoId(fileInfoId);

        return json;
    }

    /**
     * @Description 整个系统的文件比例分布
     * @author mzywucai
     * @time 2019-02-13
     * @see 
     * @return   java.lang.Object
     * @params  []
     */
    @GetMapping("/api/fileRatio")
    public Object getFileRatioAllInSystem() {
        JsonData json = fileInformationService.getFileRatioAllInSystem();

        return json;
    }

    /**
     * @Description 单个用户上传的文件分布
     * @author mzywucai
     * @time 2019-02-13
     * @see
     * @return   java.lang.Object
     * @params  []
     */
    @GetMapping("/api/user/fileRatio")
    public Object getFileRatioAboutUser(HttpSession session) {
        JsonData json = fileInformationService.getFileRatioAboutUser(session);

        return json;
    }

    /**
     * @Description 首页获取的所有文件的列表
     * @author mzywucai
     * @time 2019-02-13
     * @see 
     * @return   java.lang.Object
     * @params  [pageNum]
     */
    @PostMapping("/api/fileBasicList")
    // 不能直接注入List，包装成对象之后再注入
    public Object getFileBasicListAllInSystem(FileBasicListQueryTermsVo fileBasicListQueryTermsVo) {
        JsonData json = fileInformationService.getFileBasicListAllInSystem(fileBasicListQueryTermsVo);

        return json;
    }

    /**
     * @Description 我的获取的用户上传的文件的列表
     * @author mzywucai
     * @time 2019-02-13
     * @see
     * @return   java.lang.Object
     * @params  [pageNum]
     */
    @PostMapping("/api/user/fileBasicList")
    public Object getFileBasicListAboutUser(FileBasicListQueryTermsVo fileBasicListQueryTermsVo, HttpSession session) {
        JsonData json = fileInformationService.getFileBasicListAboutUser(fileBasicListQueryTermsVo, session);

        return json;
    }

    /**
     * @Description 用户删除文件
     * @author mzywucai
     * @time 2019-02-13
     * @see 
     * @return   java.lang.Object
     * @params  [fileInfoId]
     */
    @GetMapping("/api/user/fileDel/{fileInfoId}")
    public Object delFile(@PathVariable("fileInfoId") Long fileInfoId, HttpSession session) {
        if (null == fileInfoId) {
            fileInfoId = 0L;
        }

        JsonData json = fileInformationService.delFile(fileInfoId, session);

        return json;
    }

    /**
     * @Description 获取文件类别的节点树
     * @author mzywucai
     * @time 2019-02-13
     * @see 
     * @return   java.lang.Object
     * @params  []
     */
    @GetMapping("/api/getFileCategoryTree")
    public Object getFileCategoryTree() {
        JsonData json = fileInformationService.getFileCategoryTree();

        return json;
    }
}
